#include "smelter_rainbow.h"
#include "helper.h"
#include "debug.h"
typedef struct
{
    su16 curPosition;
    Helper_EaseInEaseOut_Context speedEase;
} Smelter_Rainbow_Context;
static Smelter_Rainbow_Context context = {.curPosition = 0};
void smelter_rainbow_restart(Config_Mode_Rainbow *rainbow)
{
    context.curPosition = 0;
    context.speedEase.target = rainbow->speed;
    context.speedEase.key = rainbow->speed;
}

Efct_Stage smelter_rainbow_process(Config_Mode_Rainbow *rainbow)
{
    //每隔1ms计算一下速度
    su16 speedCalResult = 0;
    su16 tmp;
    su16 tIndex = 0;
    su16 cIndex = 0;

    context.speedEase.target = rainbow->speed;
    helper_easeInEaseOutGenerate(&context.speedEase);
    context.curPosition = (context.curPosition + context.speedEase.key) %((su16)(gCfgFactoryPtr->enabledDotNumber)<<5); 
    speedCalResult = ((context.curPosition>>5) % gCfgFactoryPtr->enabledDotNumber) ;
    for(tmp =0;tmp<gCfgFactoryPtr->enabledDotNumber;tmp++)
    {
        tIndex = (tmp+speedCalResult)%gCfgFactoryPtr->enabledDotNumber;
        cIndex = (tmp*255)/gCfgFactoryPtr->enabledDotNumber;
        helper_wheel(cIndex,&rgbStrip.colors[tIndex]);
    }
    return E_PROCESS;
}